<% content_for :left_sidebar do  %>
  <%= render :partial => "layouts/sidebar/xiwenguanli" %>
<% end %>
<%- model_class = Notify -%>
<div class="page-header">
  <h1>通知公告列表</h1>
</div>

<%= form_tag admins_notifies_path,:method => :get do %>
    <table class="search_table">
      <tr>
        <td>稿件类型:
         <% if (current_user.admin? )  %>
        	   <%= select_tag :notify_type,options_for_select([['我的稿件',1],['平台稿件',2]],session[:notify_type]) %>
        	   <% else %>
        	    <%= select_tag :notify_type,options_for_select([['我的稿件',1]],session[:notify_type]) %>
        	 <% end %>
        
        </td>
        <td>稿件状态:
          <%= select_tag :check,options_for_select([['--请选择--',nil]] + News::CHECK.to_a,params[:check]) %>
        </td>
      </tr>
      <tr>
      		<td>来稿单位:
        	  <%= select_tag(:department, options_from_collection_for_select(@departments, "id", "name"), prompt: '请选择' )   %>
        	</td>
        	<td>
        	  发布时间:
        <%= text_field_tag :news_begin,session[:news_begin],:class => 'datepicker' %>~
        <%= text_field_tag :news_end,session[:news_end],:class => 'datepicker' %>
        
        <script type="text/javascript">
          $(document).ready(function(){
            $('.datepicker').datepicker({
                format: 'yyyy-mm-dd'
            });
          });
        </script>
          ID:
          <%= text_field_tag :notify_id,session[:notify_id] %>
        </td>
        	
        	
        	</tr>
      <tr>
        <td colspan="6">
          <%= select_button %>
          <%= new_button url: new_admins_notify_path %>
        </td>
      </tr>
    </table>
<% end %>

<table class="table table-striped">
  <thead>
    <tr>
      <th>ID</th>
      <th>标题</th>
      <th>新增时间</th>
      <th>过期时间</th>
      <th>来稿单位</th>
      <th>状态</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
    <% @notifies.each do |notify| %>
      <tr>
        <td><%= link_to notify.id, admins_notify_path(notify) %></td>
        <td><% if notify.deleted < Time.now %><font color="#FF0000">已过期</font><% end %> <%=link_to notify.title,notify_path(notify),:target => '_blank' %></td>
        <td><% if notify.pubtime.nil?  %><%= notify.created_at.strftime("%Y-%m-%d") rescue nil %> <% else %><%= notify.pubtime.strftime("%Y-%m-%d") rescue nil %><%end%></td>
       
        <td><%= notify.deleted.strftime("%Y-%m-%d") rescue nil %></td>
         <td><% if notify.contribution_units_id.nil? %><%= notify.fromwhere %><% else %><%= Department.find(notify.contribution_units_id).name %><% end %></td>
        <td>
          <% if notify.check == 0 %>
              <%= notify.check_text %>
          <% else  %>
              <%= link_to "#{notify.check_text}",admins_notify_path(notify) %>
          <% end %>
        </td>
        <td>
          <% if Notify.can_edit?(notify,@current_user) %>
              <%= link_to "编辑",edit_admins_notify_path(notify),:class => 'btn btn-default btn-xs' %>
              <%= link_to "删除",admins_notify_path(notify),
                          :method => :delete,
                          :data => { :confirm => '确定删除?' },
                          :class => 'btn btn-xs btn-danger' %>
          <% end %>
          <% if Notify.can_approve?(notify,@current_user) %>
              <%= link_to "审核",admins_notify_path(notify),:class => 'btn btn-info btn-xs' %>
          <% end %>
          <% if notify.check == 0 %>
              <%= link_to "送审",admins_notify_path(notify),:class => 'btn btn-info btn-xs' %>
          <% end %>
          
          
             <%if current_user.admin? %>

                <%=link_to '修改发布时间',"javascript:void(0)",onclick:'change_time(this)' %>
          <%end %>
          <div class="change_time" style="display:none;position: absolute;
                  margin-top: -100px;
                  margin-left: 80px;
                  border: 1px solid gray;
                  padding: 5px;
                  background: white;" >

            <%= form_for(:notify,url:change_time_admins_notify_path(notify), method:'post') do%>
                <span>输入新时间<input  type="text" name="new_time"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly/></span><br/>
                <input type="button"  name="btn" onclick="submit_it(this)" value="修改" />
            <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<div class="count">
  <%= paginate @notifies %>
</div>

<script src="/My97DatePicker/WdatePicker.js"></script>
<script>

function submit_it(obj){
   var name =$(obj).parent().find("input[name=new_time]").val();
       $(obj).parent().submit();
}
  function change_time(obj){
      var ct =$(obj).parent().find(".change_time");

      if(ct.css('display')=='none'){
          $(".change_time").hide();
          ct.show();
      }else
      {
          ct.hide();
      }

  }
</script>
